/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tpevol;

import java.util.Date;
import java.util.Random;
import tpgen.grammar.Variable;
import tpgen.grammar.Variables;
import tpgen.patterns.TransformationPattern;

/**
 *
 * @author shanki
 */
public class TpContext {
    private Random g = new Random(new Date().getTime());
    private Evaluator evaluator;
    
    public TpContext(Evaluator evaluator) {
        this.evaluator = evaluator;
    }
    
    public int randomCrosspoint(int size) {
        return size == 0 ? 0 : g.nextInt(size);
    }

    boolean randomBool(double pMutate) {
        return g.nextDouble() < pMutate;
    }
    
    public Variable randomVariable(Variables variables) {
        return variables.random(g);
    }
    
    public double evaluate(TransformationPattern tp) {
        return evaluator.eval(tp.toString());
    }
}
